package com.webtest.entity;

import lombok.Data;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;


public class Borrow {
    public static Integer maxDay =7;
    public static Map<Integer,Double> vipMap = new HashMap<>();
    static{
        vipMap.put(0,1D);
        vipMap.put(1,0.9);
        vipMap.put(2,0.8);
        vipMap.put(3,0.7);
    }
    public static  Double outPrice = 1.5;

    private Integer id;
    private Integer bookId;
    private Integer stuId;
    private Date borrowDate;        //创建时间
    private Double damages;
    private Integer status;

    public static Double calc(Borrow borrow,Book book,User user){
        Long start = borrow.getBorrowDate().getTime();
        Long end = new Date().getTime();
        Long diff = TimeUnit.DAYS.convert(end-start,TimeUnit.MILLISECONDS)+1;
        Double count = 0D;
        if(diff <= maxDay){
            count = count + diff*book.getPrice();
        }else{
            count +=maxDay * book.getPrice();
            count += (diff - maxDay) * book.getPrice()* outPrice;
        }
        if (user.getOuttime() != null && user.getOuttime().getTime() <= new Date().getTime()){
            count = count * vipMap.get(user.getVip());
        }

        return count;
    }

    public Integer getBookId() {
        return bookId;
    }

    public void setBookId(Integer bookId) {
        this.bookId = bookId;
    }

    public Integer getStuId() {
        return stuId;
    }

    public void setStuId(Integer stuId) {
        this.stuId = stuId;
    }

    public Date getBorrowDate() {
        return borrowDate;
    }

    public void setBorrowDate(Date borrowDate) {
        this.borrowDate = borrowDate;
    }

    public Double getDamages() {
        return damages;
    }

    public void setDamages(Double damages) {
        this.damages = damages;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
}
